#include "RsGisLibClbApply6sCoeElevLutPara.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibClbApply6sCoeElevLutPara::RsGisLibClbApply6sCoeElevLutPara(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibClbApply6sCoeElevLutPara();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_InputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_InputFilePath_clicked()));
	connect(ui->pushButton_DEMFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_DEMFilePath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_Apply6sCoeElevLutPara, SIGNAL(clicked()), this, SLOT(on_action_Button_Apply6sCoeElevLutPara_clicked()));

	ui->textBrowser_ParameterDescription->setText(
		"Scale Factor - is a float which can be used to scale the output pixel values(e.g., multiple by 1000), set as 1 for no scaling\nNo Data - is a float which if all bands contain that value will be ignored\nUse No Data - is a boolean as to whether the no data value specified is to be used\naX - A float for the aX coefficient\nbX - A float for the bX coefficient\ncX - A float for the cX coefficient\nGdal Format - string specifying the output image format\nDatatype - Specifying the output image pixel data type\nElev - The elevation for the element in the LUT"
	);

	ui->textBrowser_ParameterDescription->setEnabled(false);

	QStringList DatatypeList;
	DatatypeList.append("undefined");
	DatatypeList.append("8 Int");
	DatatypeList.append("16 Int");
	DatatypeList.append("32 Int");
	DatatypeList.append("64 Int");
	DatatypeList.append("8 uInt");
	DatatypeList.append("16 uInt");
	DatatypeList.append("32 uInt");
	DatatypeList.append("64 uInt");
	DatatypeList.append("32 Float");
	DatatypeList.append("64 Float");
	ui->comboBox_Datatype->addItems(DatatypeList);

	QStringList UseNoDataFlagList;
	UseNoDataFlagList.append("False");
	UseNoDataFlagList.append("True");
	ui->comboBox_UseNoData->addItems(UseNoDataFlagList);

	ui->lineEdit_InputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\LT51200352005057BJC01.tif");
	ui->lineEdit_DEMFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\DEM.tif");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\TestApply6sCoeElevLutPara.tif");
	ui->lineEdit_BandNum->setText("1");
	ui->lineEdit_ScaleFactor->setText("0.0");
	ui->lineEdit_aX->setText("0.0");
	ui->lineEdit_bX->setText("0.0");
	ui->lineEdit_cX->setText("0.0");
	ui->lineEdit_NoData->setText("0.0");
	ui->lineEdit_Elev->setText("0.0");
	ui->lineEdit_GdalFormat->setText("GTIFF");
	ui->comboBox_Datatype->setCurrentIndex(10);
	ui->comboBox_UseNoData->setCurrentIndex(0);

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibClbApply6sCoeElevLutPara::on_action_Button_InputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_InputFilePath->setText(str.toUtf8());
}

void RsGisLibClbApply6sCoeElevLutPara::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibClbApply6sCoeElevLutPara::on_action_Button_DEMFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_DEMFilePath->setText(str.toUtf8());
}

void RsGisLibClbApply6sCoeElevLutPara::on_action_Button_Apply6sCoeElevLutPara_clicked()
{
	{
		if (ui->lineEdit_InputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Input File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Output File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_aX->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "aX is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_bX->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "bX is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_cX->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "cX is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_NoData->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "No Data is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_DEMFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "DEM File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Elev->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Elev is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_ScaleFactor->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Scale Factor is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Priority->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Priority is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}
	}

	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("imageCalibration"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("Apply6sCoeElevLutPara"));
	AlgParaList << QVariant(QString(ui->lineEdit_InputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_DEMFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(double(ui->lineEdit_ScaleFactor->text().toDouble()));
	AlgParaList << QVariant(int(ui->lineEdit_BandNum->text().toInt()));
	AlgParaList << QVariant(double(ui->lineEdit_aX->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_bX->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_cX->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_Elev->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_NoData->text().toDouble()));
	AlgParaList << QVariant(int(ui->comboBox_UseNoData->currentIndex()));
	AlgParaList << QVariant(QString(ui->lineEdit_GdalFormat->text()));
	AlgParaList << QVariant(int(ui->comboBox_Datatype->currentIndex()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}
